// pages/card_receive/card_receive.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    received: false
  },

  //获取数据
  getData() {
    let that = this;
    util.request(api.ReceiveParam, {
      orderId: that.data.orderid,
    }).then(function(res) {
      if (res.errno == 0) {
        that.setData({
          bean: res.data
        })

      } else {
        util.myToast(res.errmsg)
      }
    });
  },
  //获取领取数据
  getReceiveData() {
    let that = this;
    util.request(api.ReceiveGift, {
      orderId: that.data.orderid,
    }, 'post').then(function(res) {
      if (res.errno == 0) {
        that.setData({
          received: true
        })

      } else {
        util.myToast(res.errmsg)
      }
    });
  },
  //点击立即领取
  onReceive(e) {
    this.getReceiveData();
  },
  //返回首页
  onIndex(e) {
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  //立即使用、
  onUse(e) {
    util.toClass('/pages/card_address/card_address', {
      money: this.data.bean.price,
      orderid: this.data.orderid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var orderid = options.orderid;
    var userid = options.userid;
    wx.setStorageSync("shareUserId", userid);
    this.setData({
      orderid: orderid
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})